# -*- coding: utf-8 -*-
"""
@Time    : 2021/10/9 3:06
@Author  : Leibuyun
@File    : 3.8 分数运算.py
"""

from fractions import Fraction

if __name__ == '__main__':
    a = Fraction(5, 4)  # 5/4=1.25
    b = Fraction(3, 16)  # 1/16
    c: Fraction = a + b
    print(c)  # 23/16 = 1.4375
    print(c.numerator) # 分子
    print(c.denominator) # 分母
    print(float(c))
    d = 3.75
    # 将小数转化为分数
    e = Fraction(*d.as_integer_ratio())
